<?php

namespace surface\editor;


use surface\components\FormColumn;
use surface\Functions;
use surface\Surface;

/**
 *
 * Class Editor
 *
 * @see https://www.wangeditor.com/v5/ wangeditor配置\
 *
 * props配置
 *      editorConfig: array, // 编辑器配置
 *      toolbarConfig: array, // 工具栏配置
 *      editorStyle: array, // 编辑器样式
 *      mode: string, // 富文本模式
 *
 */
class Editor extends FormColumn
{

    /**
     * @param Surface $surface
     * @param bool    $cdn      引入公共 CDN
     */
    public static function register(Surface $surface, bool $cdn = true)
    {
        $surface->register(
            Functions::create( file_get_contents(__DIR__ . "/editor.js"), ["app"])
        );

        if ($cdn) {
            $surface->addStyle('<link href="//unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">');
            $surface->addStyle('<style>#editor—wrapper {border: 1px solid #ccc;border-top: 5px solid #595959;}#toolbar-container { border-bottom: 1px solid #ccc; }</style>');
            $surface->addScript('<script src="//unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>');
        }
    }


}

